﻿using B.S.Backtrack.Domain.Entities;
using B.S.Backtrack.ErrorCode;
using B.S.Backtrack.Infrastructure.Interface;
using B.S.Backtrack.Write.API.Application.Command.Cultures;
using B.S.Backtrack.Write.API.Application.Command.Image;
using MediatR;
using System.IO.Pipelines;

namespace B.S.Backtrack.Write.API.Application.CommandHandler.Cultures
{
    public class DelHealthHandler : IRequestHandler<DelHealthCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<Health> heaRep;

        public DelHealthHandler(IBaseRepository<Health> heaRep)
        {
            this.heaRep = heaRep;
        }
        public Task<ApiResult<int>> Handle(DelHealthCommand request, CancellationToken cancellationToken)
        {
            ApiResult<int> result = new ApiResult<int>();
            var pro = heaRep.GetAll().Where(x => x.HealthId == request.HealthId).FirstOrDefault();
            if (pro != null)
            {
                pro.IsDel = true;
                heaRep.Update(pro);
            }

            result.Code = ApiEnums.删除成功;
            result.Msg = ApiEnums.删除成功.ToString();
            result.Data = 1;
            return Task.FromResult(result);
        }
    }
}
